import { getGameFlowApi } from '@/api/client/basicDataApi'
// 游戏流
import { useClientStore } from '@/stores/client'
import { useMessageListStore } from '@/stores/messgelist'

export default class GameFlow {
  private gameFlow: any

  constructor() {
    this.gameFlow = {}
    // 监听对局情况和人员变化
    useMessageListStore().addMessage({
      name: 'Gameflow',
      trigger: ({ data }) => {
        this.formatGameFlow(data)
      },
    })
  }

  // 获取游戏流数据
  getCurrentGameFlow() {
    getGameFlowApi().then((data) => {
      this.formatGameFlow(data)
    })
  }

  //   整理获取的游戏流数据
  formatGameFlow(data) {
    // data.phase: 'NONE' 未开始 | 'Lobby' 大厅（房间内）| 'ChampSelect' 英雄选择
    console.log('游戏流更新：', data)
    this.gameFlow = data
    useClientStore().gameflow = data
  }
}
